from urllib2 import urlopen
from lxml import etree
import os
class AsxParser(object):
	def parse(self):
		root=urlopen(self.asxsrc).read()
		root=etree.HTML(root)
		refs=root.xpath(".//ref")
		for ref in refs:
			href=ref.get('href','')
			if href.endswith('.asx'):
				self.asxsrc=href
				self.parse()
			else:
				self.playlist.append(href)
		return self.playlist
	def __init__(self,asxfile):
		if os.path.isfile(asxfile):
			self.asxsrc=open(asxfile).read().strip()
		else:
			self.asxsrc=asxfile
		self.playlist=[]
	
if __name__=='__main__':
	import sys
	ap=AsxParser(sys.argv[1])
	import pdb;pdb.set_trace()
	ap.parse()
	print ap.playlist
